package com.classtest.classtestdemo.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.classtest.classtestdemo.bean.DbUser;
import com.classtest.classtestdemo.mapper.DbUserMapper;
import com.classtest.classtestdemo.service.DbUserService;
import com.classtest.classtestdemo.utlis.PKGeneration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DbUserServiceImpl extends ServiceImpl<DbUserMapper, DbUser> implements DbUserService {
    @Autowired
    DbUserMapper dbUserMapper;

    @Override
    public void userSignUpInsertAll(@Param("DbUser") String dbU) {
            DbUser dbUser= JSONObject.parseObject(dbU, DbUser.class);
//        dbUser dbUser = new dbUser();
            dbUser.setId(PKGeneration.INSTANCE.nextId());
            dbUserMapper.userSignUpInsert(dbUser);
//        dbUser.setUserTName(dbUserJsonOnject.getString("userTName"));
//        dbUser.setRedistrationType(dbUserJsonOnject.getString("redistrationType"));
//        dbUser.setIdCard(dbUserJsonOnject.getString("IdCard"));
//        dbUser.setUserIdCard(dbUserJsonOnject.getString("userIdCard"));
//        dbUser.setUserBrithday(dbUserJsonOnject.getDate("userBrithday"));
//        dbUser.setAddress(dbUserJsonOnject.getString("address"));
    }

    @Override
    public boolean exitUserNameInAll(String dbU) {
        DbUser dbUser= JSONObject.parseObject(dbU, DbUser.class);
        if (dbUserMapper.exitUserName(dbUser)){
            return false;
        }
        return true;
    }

    @Override
    public List<DbUser> userLogin(String dbU) {
        DbUser dbUser= JSONObject.parseObject(dbU, DbUser.class);
        List<DbUser> dbUser1 = dbUserMapper.userLogin(dbUser);
        return dbUser1;
    }
}
